// pages/groups/index.js
Page({
  data: {
    groups: [
      {
        id: 1,
        name: "城旅·成都①群",
        avatar: "/assets/img/message/mountain.png",
        members: 128,
        online: 45,
        description: "成都本地生活交流群，分享美食、景点、活动",
        tags: ["成都", "本地", "生活"],
        category: "本地生活"
      },
      {
        id: 2,
        name: "美食探店团",
        avatar: "/assets/img/message/phone.png",
        members: 89,
        online: 23,
        description: "一起发现城市隐藏美食，分享探店心得",
        tags: ["美食", "探店", "分享"],
        category: "美食"
      },
      {
        id: 3,
        name: "摄影爱好者协会",
        avatar: "/assets/img/message/draw.png",
        members: 156,
        online: 34,
        description: "摄影技巧交流，外拍活动组织",
        tags: ["摄影", "艺术", "外拍"],
        category: "摄影"
      },
      {
        id: 4,
        name: "户外运动俱乐部",
        avatar: "/assets/img/message/computer.png",
        members: 203,
        online: 67,
        description: "徒步、骑行、登山等户外运动交流",
        tags: ["户外", "运动", "健康"],
        category: "运动"
      },
      {
        id: 5,
        name: "读书分享会",
        avatar: "/assets/img/message/swim.png",
        members: 76,
        online: 12,
        description: "好书推荐，读书心得分享",
        tags: ["读书", "学习", "分享"],
        category: "学习"
      }
    ],
    categories: [
      { name: "全部", active: true },
      { name: "本地生活", active: false },
      { name: "美食", active: false },
      { name: "摄影", active: false },
      { name: "运动", active: false },
      { name: "学习", active: false }
    ]
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '发现群组'
    })
  },

  onGroupTap: function(e) {
    const group = e.currentTarget.dataset.group
    
    wx.showModal({
      title: group.name,
      content: `成员：${group.members}人（${group.online}人在线）\n分类：${group.category}\n描述：${group.description}\n标签：${group.tags.join('、')}`,
      showCancel: true,
      cancelText: '关闭',
      confirmText: '加入群组',
      success: function(res) {
        if (res.confirm) {
          wx.showToast({
            title: '加入群组成功',
            icon: 'success'
          })
        }
      }
    })
  },

  onCategoryTap: function(e) {
    const index = e.currentTarget.dataset.index
    const categories = this.data.categories.map((item, i) => {
      item.active = i === index
      return item
    })
    this.setData({ categories })
    
    wx.showToast({
      title: '筛选：' + categories[index].name,
      icon: 'none'
    })
  },

  onCreateGroupTap: function() {
    wx.showModal({
      title: '创建群组',
      content: '确定要创建新群组吗？',
      success: function(res) {
        if (res.confirm) {
          wx.showToast({
            title: '创建群组功能开发中',
            icon: 'none'
          })
        }
      }
    })
  }
})
